/**
 * @Author: hrg
 * @Date: 2023-11-29 14:06:30
 * @LastEditTime: 2023-12-14 09:22:11
 * @FilePath: \easy_dashboard\web\src\route\permission.js
 * @Description: 
 */
/*
 * @Date: 2021-11-30 15:42:07
 * @LastEditors: 春贰
 * @Desc:
 * @LastEditTime: 2023-11-28 16:13:18
 * @FilePath: \web\src\route\permission.js
 */
 
import NProgress from "nprogress";
import router from "@/route/index";  
import { getCurrentInstance } from "vue";
import { setStorage, StorageName, getStorage } from "@/tools/storage.js";
  
/**
 * 前置拦截
 *
 * @param to    前往路由
 * @param from  来至路由
 * @param next  放行路由
 */

export var permissionController = async (to, from, next) => {
  NProgress.start(); 
  // 检测登录
  //是否有token
  let isToken =  getStorage(StorageName.user_token)   
  // let isToken  = true ;//模拟
  if (!to.fullPath.includes("login") && !isToken) {
    next({ path: "/login" });
  } else {
    // 基本路由 是否包括 前往路由 ,不包括就去查询 更新
    if (
      !router
        .getRoutes()
        .map((it) => it.path)
        .includes(to.path)
    ) {  
      next("/");
    } else {
      next();
    }
  }
};
